//
// Description: 274. H 指数
// Created by Loading on 2025/3/2.
//

#include <bits/stdc++.h>

using namespace std;

int hIndex(vector<int>& citations) {
    sort(citations.begin(), citations.end());

    int n = citations.size();

    for (int i = 0; i < n; ++i) {
        // 排序后数组，引用次数大于等于数组余量，说明已找到最大值h，值为数组余量
        if (citations[i] >= n - i) {
            return n - i;
        }
    }

    return 0;
}

int main() {
    vector<int> citations{3, 0, 6, 1, 5};

    int h = hIndex(citations);

    cout << h << endl;

    return 0;
}
